package com.example.mntz.service.Impl;

import com.example.mntz.dao.UserMapper;
import com.example.mntz.model.LayuiTable;
import com.example.mntz.model.User;
import com.example.mntz.model.UserExample;
import com.example.mntz.model.Zq;
import com.example.mntz.service.UserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper mapper;
    @Override
    public LayuiTable selectUserLists(Integer limit, Integer page, User user) {
        Page page1 = PageHelper.startPage(page, limit);
        List<User> users= mapper.selectByUser(user);
        LayuiTable<User> layuiTable = new LayuiTable<>();
        layuiTable.setData(users);
        layuiTable.setCount(page1.getTotal());
        return layuiTable;
    }


    @Override
    public User selectUserById(Integer uId) {
        return mapper.selectByPrimaryKey(uId);
    }

    @Override
    public void insertUser(User user) {
        if(user.getuId() != null ){
            mapper.updateByPrimaryKey(user);
        }else {
            mapper.insert(user);
        }
    }

    @Override
    @Transactional
    public void deleteUsers(List<Integer> uIds) {
        for(Integer u :uIds){

            mapper.deleteByPrimaryKey(u);
        }
    }
}
